home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / rexx / QuickMsg.lha / QuickMsg / English / QuickMsg.rexx < prev   
OS/2 REXX Batch file  |  2002-09-26  |  7KB  |  293 lines

  1. /* $VER: QuickMsg.rexx 1.0 (26-Sep-2002) English by A. Greve */
  2.  
  3. SIGNAL ON break_c
  4. SIGNAL ON failure
  5. SIGNAL ON halt
  6. SIGNAL ON ioerr
  7. SIGNAL ON syntax
  8.  
  9. tri = 0
  10. quo = '22'x; apo = '27'x
  11.  
  12. PARSE ARG Msg
  13.  
  14. IF Msg = '?' THEN SIGNAL Templates
  15.  
  16. KeyW = UPPER(WORD(Msg, 1))
  17. IF (KeyW == 'FROM') | (KeyW == 'FILE') THEN DO
  18.     IF LEFT(WORD(Msg, 2), 1) == quo THEN DO
  19.         p1 = 0; p2 = 0
  20.         DO i = 6 FOR LENGTH(Msg)
  21.             IF SUBSTR(Msg, i, 1) == quo THEN DO
  22.                 p1 = i; LEAVE
  23.             END
  24.         END
  25.         DO i = p1 + 1 FOR LENGTH(Msg)
  26.             IF SUBSTR(Msg, i, 1) == quo THEN DO
  27.                 p2 = i; LEAVE
  28.             END
  29.         END
  30.         IF p1 == 0 | p2 == 0 | (p2 - p1) <= 0 THEN DO
  31.             SAY 'QuickMsg: Parsing the filename failed!'
  32.             EXIT(0)
  33.         END
  34.         FName = SUBSTR(Msg, p1 + 1, p2 - p1 - 1)
  35.     END
  36.     ELSE DO
  37.         FName = WORD(Msg, 2)
  38.         p2 = WORDINDEX(Msg, 2) + LENGTH(FName) - 1
  39.     END
  40.     IF OPEN('RBuffer', FName, 'R') THEN DO
  41.         IF KeyW == 'FROM' THEN DO
  42.             Msg = READLN('RBuffer')
  43.             CLOSE('RBuffer')
  44.         END
  45.         ELSE DO
  46.             i = 0; il = 0
  47.             DO UNTIL EOF('RBuffer')
  48.                 i = i + 1
  49.                 FileIn.i = READLN('RBuffer')
  50.                 il = MAX(il, LENGTH(FileIn.i))
  51.             END
  52.             CLOSE('RBuffer')
  53.             MsgH = ''
  54.             IF i > 1 THEN DO
  55.                 DO ih = 1 TO i
  56.                     FileIn.ih = FileIn.ih || COPIES(' ', il - LENGTH(FileIn.ih))  || '\n'
  57.                 END
  58.                 FileIn.ih = LEFT(FileIn.ih, LENGTH(FileIn.ih) - 2)
  59.                 IF STRIP(FileIn.ih) == '' THEN DO
  60.                     FileIn.ih = ''
  61.                     ih = ih - 1
  62.                     FileIn.ih = LEFT(FileIn.ih, LENGTH(FileIn.ih) - 2)
  63.                     IF STRIP(FileIn.ih) == '' THEN FileIn.ih = ''
  64.                 END
  65.                 DO ih = 1 TO i
  66.                     IF FileIn.ih ~= '' THEN DO
  67.                         Flag = 1
  68.                         IF ih = i THEN Flag = LENGTH(TRIM(LEFT(FileIn.ih, LENGTH(FileIn.ih) - 2)))
  69.                         IF Flag > 0 THEN MsgH = MsgH || FileIn.ih
  70.                     END
  71.                 END
  72.                 MsgH = LEFT(MsgH, LENGTH(MsgH) - 2)
  73.             END
  74.             ELSE MsgH = FileIn.1
  75.             IF RIGHT(MsgH, 1) == ' ' THEN MsgH = OVERLAY('a0'x, MsgH, LENGTH(MsgH))
  76.             Msg = DELSTR(Msg, 1, p2)
  77.             Msg = INSERT(MsgH, Msg, 0)
  78.             DROP FileIn. MsgH
  79.         END
  80.     END
  81.     ELSE DO
  82.         SAY 'QuickMsg: Could not open »'FName'« !'
  83.         EXIT(0)
  84.     END
  85. END
  86.  
  87. w = WORDS(Msg); pd = LENGTH(Msg); pp = pd; pm = pd; pw = pd; ph = pd
  88. DO i = 1 FOR w
  89.     j = WORD(Msg, i); pj = WORDINDEX(Msg, i); k = LEFT(j, 2)
  90.     IF UPPER(k) == 'M=' THEN DO
  91.         m1 = RIGHT(j, LENGTH(j) - 2)
  92.         IF DATATYPE(m1, 'w') THEN DO
  93.             ChMode = m1
  94.             pm = WORDINDEX(Msg, i) - 1
  95.         END
  96.     END
  97.     IF UPPER(k) == 'D=' THEN DO
  98.         k1 = RIGHT(j, LENGTH(j) - 2)
  99.         IF DATATYPE(k1, 'w') THEN DO
  100.             DelSecs = k1
  101.             pd = WORDINDEX(Msg, i) - 1
  102.         END
  103.     END
  104.     IF UPPER(k) == 'P=' THEN DO
  105.         pj1 = pj + 2
  106.         IF SUBSTR(Msg, pj1, 1) = quo THEN DO
  107.             pj2 = 0
  108.             DO ih = pj1 + 1 FOR pd
  109.                 IF SUBSTR(Msg, ih, 1) == quo THEN DO
  110.                     pj2 = ih - 1; LEAVE
  111.                 END
  112.             END
  113.             IF pj2 > pj1 THEN DO
  114.                 PubScreen = SUBSTR(Msg, pj1 + 1, pj2 - pj1)
  115.                 pp = pj1 - 3
  116.             END
  117.         END
  118.         ELSE DO
  119.             PubScreen = RIGHT(j, LENGTH(j) - 2)
  120.             pp = WORDINDEX(Msg, i) - 2
  121.         END
  122.     END
  123.     IF UPPER(k) == 'W=' THEN DO
  124.         w1 = RIGHT(j, LENGTH(j) - 2)
  125.         IF DATATYPE(w1, 'w') THEN DO
  126.             MaxW = w1
  127.             pw = WORDINDEX(Msg, i) - 1
  128.         END
  129.     END
  130.     IF UPPER(k) == 'H=' THEN DO
  131.         h1 = RIGHT(j, LENGTH(j) - 2)
  132.         IF DATATYPE(h1, 'w') THEN DO
  133.             MaxH = h1
  134.             ph = WORDINDEX(Msg, i) - 1
  135.         END
  136.     END
  137. END
  138. p = MIN(pd, pp, pm, pw, ph)
  139. IF p < LENGTH(Msg) THEN Msg = TRIM(LEFT(Msg, p))
  140.  
  141. IF DelSecs == 'DELSECS' | DelSecs <= 0 THEN DelSecs = 2
  142. IF ChMode == 'CHMODE' | ChMode < 0 | ChMode > 4 THEN ChMode = 0
  143. IF MaxW == 'MAXW' | MaxW < 0 THEN MaxW = 0
  144. IF MaxH == 'MAXH' | MaxH < 0 THEN MaxH = 0
  145.  
  146. Buffer = Msg
  147.  
  148. i1 = LENGTH(Msg)
  149. IF i1 > 0 THEN DO
  150.     DO i = 1 FOR i1
  151.         IF SUBSTR(Msg, i, 1) == quo THEN Msg = OVERLAY(apo, Msg, i, 1)
  152.     END
  153. END
  154.  
  155. i = 1
  156. DO FOREVER
  157.     j = INDEX(Msg, '\n')
  158.     IF j > 0 THEN DO
  159.         MsgY.i = LEFT(Msg, j - 1)
  160.         Msg = RIGHT(Msg, LENGTH(Msg) - j - 1)
  161.         i = i + 1
  162.     END
  163.     ELSE DO
  164.         MsgY.i = Msg; LEAVE
  165.     END
  166. END
  167.  
  168. IF MaxW ~= 0 THEN DO
  169.     jh = 0
  170.     DO j = 1 FOR i
  171.         jh = jh + 1
  172.         tmp = MsgY.j
  173.         DO FOREVER
  174.             IF LENGTH(tmp) > MaxW THEN DO
  175.                 MsgX.jh = LEFT(tmp, MaxW)
  176.                 tmp = RIGHT(tmp, LENGTH(tmp) - MaxW)
  177.                 jh = jh + 1
  178.             END
  179.             ELSE DO
  180.                 MsgX.jh = tmp; LEAVE
  181.             END
  182.         END
  183.     END
  184.     i = jh
  185. END
  186. ELSE DO
  187.     DO j = 1 FOR i
  188.         MsgX.j = MsgY.j
  189.     END
  190. END
  191. DROP MsgY.
  192.  
  193. IF MaxH ~= 0 THEN i = MIN(i, MaxH)
  194.  
  195. CALL SetAppInfo()
  196.  
  197. wintags_t = ''
  198. DO j = 1 FOR i
  199.     SELECT
  200.         WHEN ChMode = 0 THEN wintags_t = wintags_t || ' 'TextN('  'MsgX.j'  ')' '
  201.         WHEN ChMode = 1 THEN wintags_t = wintags_t || ' 'TextH('  'MsgX.j'  ')' '
  202.         WHEN ChMode = 2 THEN wintags_t = wintags_t || ' 'TextB('  'MsgX.j'  ')' '
  203.         WHEN ChMode = 3 THEN wintags_t = wintags_t || ' 'Text3('  'MsgX.j'  ')' '
  204.         WHEN ChMode = 4 THEN wintags_t = wintags_t || ' 'TextT('  'MsgX.j'  ')' '
  205.         OTHERWISE
  206.     END
  207. END
  208.  
  209. IF ~SHOW('L', 'tritonrexx.library') THEN DO
  210.     IF ~ADDLIB('tritonrexx.library', 10, -30, 0) THEN DO
  211.         SAY Buffer
  212.         EXIT(0)
  213.     END
  214. END
  215. IF ~SHOW('L', 'rexxsupport.library') THEN DO
  216.     IF ~ADDLIB('rexxsupport.library', 10, -30, 0) THEN DO
  217.         SAY Buffer
  218.         EXIT(0)
  219.     END
  220. END
  221. tri = 1
  222. app = NULL()
  223.  
  224. wintags_a = WindowID(1),
  225.     WindowFlags('TRWF_NODRAGBAR|TRWF_NODEPTHGADGET|TRWF_NOCLOSEGADGET|TRWF_NOZIPGADGET|TRWF_NOSIZEGADGET|TRWF_NOMINTEXTWIDTH'),
  226.     WindowPosition('TRWP_CENTERDISPLAY'),
  227.     PubScreenName(PubScreen),
  228.     'VertGroupC',
  229.     'Space'
  230. wintags_e = 'Space',
  231.     'EndGroup',
  232.     'EndProject'
  233.  
  234. app = TR_CREATEAPP('TRCA_Name'     '"'appname'"',
  235.                    'TRCA_LongName' '"'applongname'"',
  236.                    'TRCA_Info'     '"'appinfo'"',
  237.                    'TRCA_Version'  '"'appversion'"',
  238.                    'TRCA_Release'  '"'apprelease'"',
  239.                    'TRCA_Date'     '"'appdate'"',
  240.                    'TAG_END')
  241. IF app ~= NULL() THEN window = TR_OPENPROJECT(app, wintags_a || wintags_t || wintags_e)
  242.  
  243. IF window ~= NULL() THEN DO
  244.     CALL DELAY(DelSecs * 50)
  245.     CALL TR_CLOSEPROJECT(window)
  246. END
  247. ELSE SAY Buffer
  248.  
  249. CALL TR_DELETEAPP(app)
  250. IF tri THEN CALL DELETE('ENV:Triton/QuickMsg.win.1')
  251. EXIT(0)
  252.  
  253. SetAppInfo:
  254.     appname     = 'QuickMsg'
  255.     applongname = 'QuickMsg ENG - ©2002 von Axel Greve'
  256.     appinfo     = 'Shows a quick message on the desired PubScreen'
  257.     appversion  = '1.0'
  258.     apprelease  = '1'
  259.     appdate     = '26-Sep-2002'
  260. RETURN 0
  261.  
  262. Templates:
  263.     CALL SetAppInfo()
  264.     SAY appname'.rexx 'appversion' ('appdate') - 'appinfo
  265.     SAY 'This program can be called in 3 different ways:'
  266.     SAY '1.)   rx QuickMsg.rexx <Text> [D=<Seconds>] [P=<PubScreen>] [M=<Textformat>] [W=<Width>] [H=<Height>]'
  267.     SAY '2.)   rx QuickMsg.rexx FILE <Filename> [D=<Seconds>] [P=<PubScreen>] [M=<Textformat>] [W=<Width>] [H=<Height>]'
  268.     SAY '3.)   rx QuickMsg.rexx FROM <Filename>'
  269.     SAY 'Where:'
  270.     SAY '  <Text>       = The text to be displayed   (String)  f. ex. Couldn''t find file!'
  271.     SAY '  <Filename>   = Path and filename          (String)  f. ex. FILE t:tempfile'
  272.     SAY '  <Filename>   = Path and filename          (String)  f. ex. FROM 'quo't:temp file'quo
  273.     SAY '  <Seconds>    = Display time in seconds    (Integer) f. ex. D=5'
  274.     SAY '  <PubScreen>  = Name of PubScreen          (String)  f. ex. P=Workbench'
  275.     SAY '  <PubScreen>  = Name of PubScreen          (String)  f. ex. P='quo'Test Screen'quo
  276.     SAY '  <Textformat> = See description            (Integer) f. ex. M=2'
  277.     SAY '  <Width>      = Max. textwidth in columns  (Integer) f. ex. W=20'
  278.     SAY '  <Height>     = Max. textheight in lines   (Integer) f. ex. H=5'
  279.     SAY '<Text> or FILE <Filename> always must be the first argument, the further'
  280.     SAY 'arguments are optional and their order is unimportant. Leaving out all'
  281.     SAY 'arguments will open an empty window on the Workbench screen for 2 seconds.'
  282. EXIT(0)
  283.  
  284. break_c:
  285. failure:
  286. halt:
  287. ioerr:
  288. syntax:
  289.     SAY '+++ Error 'rc' in line 'sigl' - 'ERRORTEXT(rc)
  290.     SAY SOURCELINE(sigl)
  291.     IF app ~= '00000000'x THEN CALL TR_DELETEAPP(app)
  292.     EXIT(10)
  293.